package com.ztjc.day03_simpleadapter;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * SimpleAdapter的使用
 */
public class MainActivity extends Activity {

    private ListView lvList;
    private SimpleAdapter simpleAdapter;
    private List<Map<String, String>> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lvList = (ListView) findViewById(R.id.lv_list);

        createData();
    }

    /**
     * 创建虚拟的数据
     */
    private void createData() {
        data = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("category", "书籍分类" + 1);
        data.add(map);
        Map<String, String> map2 = new HashMap<>();
        map2.put("category", "书籍分类" + 2);
        data.add(map2);
        Map<String, String> map3 = new HashMap<>();
        map3.put("category", "书籍分类" + 3);
        data.add(map3);
        Map<String, String> map4 = new HashMap<>();
        map4.put("category", "书籍分类" + 4);
        data.add(map4);
        Map<String, String> map5 = new HashMap<>();
        map5.put("category", "书籍分类" + 5);
        data.add(map5);
        Map<String, String> map6 = new HashMap<>();
        map6.put("category", "书籍分类" + 6);
        data.add(map6);
        simpleAdapter = new SimpleAdapter(this, data, R.layout.list_item, new String[]{"category"}, new int[]{R.id.tv_category});
        lvList.setAdapter(simpleAdapter);
    }

}
